--
-- PostgreSQL database dump
--

SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;

--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: 
--

CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;


--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';


--
-- Name: plpythonu; Type: EXTENSION; Schema: -; Owner: 
--

CREATE EXTENSION IF NOT EXISTS plpythonu WITH SCHEMA pg_catalog;


--
-- Name: EXTENSION plpythonu; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION plpythonu IS 'PL/PythonU untrusted procedural language';


SET search_path = public, pg_catalog;

--
-- Name: ldap_pendency_actions_enum; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE ldap_pendency_actions_enum AS ENUM (
    'ADD',
    'MODIFY',
    'DEL'
);


ALTER TYPE public.ldap_pendency_actions_enum OWNER TO postgres;

--
-- Name: resources_enum; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE resources_enum AS ENUM (
    'node',
    'channel'
);


ALTER TYPE public.resources_enum OWNER TO postgres;

--
-- Name: ldap_add(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION ldap_add() RETURNS trigger
    LANGUAGE plpythonu
    AS $_$import ldap

import ldap.modlist as modlist

try:

	# Get LDAP configuration

	get_config = plpy.prepare("SELECT value FROM configurations WHERE name = $1", ["text"]);

	LDAP_HOST = plpy.execute(get_config, ["LDAP_HOST"]);

	LDAP_PORT = plpy.execute(get_config, ["LDAP_PORT"]);

	LDAP_USER_TO_BIND = plpy.execute(get_config, ["LDAP_USER_TO_BIND"]);

	LDAP_PASS_TO_BIND = plpy.execute(get_config, ["LDAP_PASS_TO_BIND"]);

	LDAP_TREE = plpy.execute(get_config, ["LDAP_TREE"]);

	l = ldap.open(LDAP_HOST[0]["value"], port=int(LDAP_PORT[0]["value"]));

	l.protocol_version = ldap.VERSION3;

	l.simple_bind_s(LDAP_USER_TO_BIND[0]["value"], LDAP_PASS_TO_BIND[0]["value"]);

	dn = 'uid=' + TD["new"]["username"] + ',ou=people,' + LDAP_TREE[0]["value"];

	attrs = {};

	attrs['cn'] = TD["new"]["username"];

	attrs['gidnumber'] = str(TD["new"]["gidnumber"]);

	attrs['homedirectory'] = TD["new"]["homedirectory"];

	attrs['objectClass'] = ['top','person','inetOrgPerson','posixAccount','eduPerson','brPerson','schacPersonalCharacteristics','fibre'];

	attrs['sn'] = TD["new"]["name"];

	attrs['uidnumber'] = str(TD["new"]["id"]);

	attrs['uid'] = TD["new"]["username"];

	attrs['eduPersonPrincipalName'] = TD["new"]["username"];

	attrs['mail'] = TD["new"]["email"];

	attrs['userpassword'] = TD["new"]["password"];

	attrs['loginShell'] = TD["new"]["loginshell"];

	if (TD["new"]["enable"]):

		attrs['userEnable'] = 'TRUE';

	else:

		attrs['userEnable'] = 'FALSE';

	if (TD["new"]["admin"]):

		attrs['omfAdmin'] = 'TRUE';

	else:

		attrs['omfAdmin'] = 'FALSE';

	ldif = modlist.addModlist(attrs);

	l.add_s(dn,ldif);

	l.unbind_s();

except (ldap.LDAPError, plpy.SPIError), e:

	# Insert the LDAP pendency to the database.

	insert_pendency = plpy.prepare("INSERT INTO ldap_pendency (action, user_id, username, password, name, email, public_key, enable, admin, homedirectory, gidnumber, loginshell, error_description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)", ["ldap_pendency_actions_enum", "int", "text", "text", "text", "text", "text", "boolean", "boolean", "text", "int", "text", "text"]);

	pendency_data = [];

	pendency_data.append("ADD");

	pendency_data.append(TD["new"]["id"]);

	pendency_data.append(TD["new"]["username"]);

	pendency_data.append(TD["new"]["password"]);

	pendency_data.append(TD["new"]["name"]);

	pendency_data.append(TD["new"]["email"]);

	pendency_data.append(TD["new"]["public_key"]);

	pendency_data.append(TD["new"]["enable"]);

	pendency_data.append(TD["new"]["admin"]);

	pendency_data.append(TD["new"]["homedirectory"]);

	pendency_data.append(TD["new"]["gidnumber"]);

	pendency_data.append(TD["new"]["loginshell"]);

	pendency_data.append(str(e.message["desc"]));

	insert = plpy.execute(insert_pendency, pendency_data);

	# Send LDAP error notification.

	plpy.execute("SELECT ldap_error_notify()");$_$;


ALTER FUNCTION public.ldap_add() OWNER TO postgres;

--
-- Name: ldap_del(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION ldap_del() RETURNS trigger
    LANGUAGE plpythonu
    AS $_$import ldap

try:

	# Get LDAP configuration

	get_config = plpy.prepare("SELECT value FROM configurations WHERE name = $1", ["text"]);

	LDAP_HOST = plpy.execute(get_config, ["LDAP_HOST"]);

	LDAP_PORT = plpy.execute(get_config, ["LDAP_PORT"]);

	LDAP_USER_TO_BIND = plpy.execute(get_config, ["LDAP_USER_TO_BIND"]);

	LDAP_PASS_TO_BIND = plpy.execute(get_config, ["LDAP_PASS_TO_BIND"]);

	LDAP_TREE = plpy.execute(get_config, ["LDAP_TREE"]);

	l = ldap.open(LDAP_HOST[0]["value"], port=int(LDAP_PORT[0]["value"]));

	l.protocol_version = ldap.VERSION3;

	l.simple_bind_s(LDAP_USER_TO_BIND[0]["value"], LDAP_PASS_TO_BIND[0]["value"]);

	deleteDN = 'uid=' + TD["old"]["username"] + ',ou=people,' + LDAP_TREE[0]["value"];

	l.delete_s(deleteDN);

	l.unbind_s();

except (ldap.LDAPError, plpy.SPIError), e:

	# Insert the LDAP pendency to the database.

	insert_pendency = plpy.prepare("INSERT INTO ldap_pendency (action, user_id, username, password, name, email, public_key, enable, admin, homedirectory, gidnumber, loginshell, error_description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)", ["ldap_pendency_actions_enum", "int", "text", "text", "text", "text", "text", "boolean", "boolean", "text", "int", "text", "text"]);

	pendency_data = [];

	pendency_data.append("DEL");

	pendency_data.append(TD["old"]["id"]);

	pendency_data.append(TD["old"]["username"]);

	pendency_data.append(TD["old"]["password"]);

	pendency_data.append(TD["old"]["name"]);

	pendency_data.append(TD["old"]["email"]);

	pendency_data.append(TD["old"]["public_key"]);

	pendency_data.append(TD["old"]["enable"]);

	pendency_data.append(TD["old"]["admin"]);

	pendency_data.append(TD["old"]["homedirectory"]);

	pendency_data.append(TD["old"]["gidnumber"]);

	pendency_data.append(TD["old"]["loginshell"]);

	pendency_data.append(str(e.message["desc"]));

	insert = plpy.execute(insert_pendency, pendency_data);

	# Send LDAP error notification.

	plpy.execute("SELECT ldap_error_notify()");$_$;


ALTER FUNCTION public.ldap_del() OWNER TO postgres;

--
-- Name: ldap_error_notify(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION ldap_error_notify() RETURNS boolean
    LANGUAGE plpythonu
    AS $$import smtplib

receivers = plpy.execute("SELECT name, email FROM \"user\" WHERE admin = true");

sender = receivers[0];

subject = "Testbed LDAP error.";

# Creating the message body

message_body = "From: " + sender['name'] + " <" + sender['email'] + ">\n";

message_body += "To:";

receivers_email = [];

for receiver in receivers:

	receivers_email.append(receiver['email']);

	message_body += " " + receiver['name'] + " <" + receiver['email'] + ">";

	if(receiver != receivers[len(receivers)-1]):

		message_body += ",";

message_body += "\n";

message_body += "MIME-Version: 1.0\n";

message_body += "Content-type: text/html\n";

message_body += "Subject: " + subject + "\n\n";

# Message:

message_body += "The replication of data for LDAP server in your testbed has failed.<br>";

message_body += "Try to replicate the data manually in the LDAP pending panel on your LS-WEB interface.<br>";

try:

	smtpObj = smtplib.SMTP('localhost')

	smtpObj.sendmail(sender['email'], receivers_email, message_body);

	return True;

except:

	return False;$$;


ALTER FUNCTION public.ldap_error_notify() OWNER TO postgres;

--
-- Name: ldap_modify(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION ldap_modify() RETURNS trigger
    LANGUAGE plpythonu
    AS $_$import ldap

import ldap.modlist as modlist

try:

	# Get LDAP configuration

	get_config = plpy.prepare("SELECT value FROM configurations WHERE name = $1", ["text"]);

	LDAP_HOST = plpy.execute(get_config, ["LDAP_HOST"]);

	LDAP_PORT = plpy.execute(get_config, ["LDAP_PORT"]);

	LDAP_USER_TO_BIND = plpy.execute(get_config, ["LDAP_USER_TO_BIND"]);

	LDAP_PASS_TO_BIND = plpy.execute(get_config, ["LDAP_PASS_TO_BIND"]);

	LDAP_TREE = plpy.execute(get_config, ["LDAP_TREE"]);

	l = ldap.open(LDAP_HOST[0]["value"], port=int(LDAP_PORT[0]["value"]));

	l.protocol_version = ldap.VERSION3;

	l.simple_bind_s(LDAP_USER_TO_BIND[0]["value"], LDAP_PASS_TO_BIND[0]["value"]);

	dn = 'uid=' + TD["old"]["username"] + ',ou=people,' + LDAP_TREE[0]["value"];

	# OLD data

	old = {};

	old['cn'] = TD["old"]["username"];

	old['gidnumber'] = str(TD["old"]["gidnumber"]);

	old['homedirectory'] = TD["old"]["homedirectory"];

	old['sn'] = TD["old"]["name"];

	old['uid'] = TD["old"]["username"];

	old['eduPersonPrincipalName'] = TD["old"]["username"];

	old['mail'] = TD["old"]["email"];

	old['userpassword'] = TD["old"]["password"];

	old['loginShell'] = TD["old"]["loginshell"];

	if (TD["old"]["enable"]):

		old['userEnable'] = 'TRUE';

	else:

		old['userEnable'] = 'FALSE';

	if (TD["old"]["admin"]):

		old['omfAdmin'] = 'TRUE';

	else:

		old['omfAdmin'] = 'FALSE';

	# NEW data

	new = {};

	new['cn'] = TD["new"]["username"];

	new['gidnumber'] = str(TD["new"]["gidnumber"]);

	new['homedirectory'] = TD["new"]["homedirectory"];

	new['sn'] = TD["new"]["name"];

	new['uid'] = TD["new"]["username"];

	new['eduPersonPrincipalName'] = TD["new"]["username"];

	new['mail'] = TD["new"]["email"];

	new['userpassword'] = TD["new"]["password"];

	new['loginShell'] = TD["new"]["loginshell"];

	if (TD["new"]["enable"]):

		new['userEnable'] = 'TRUE';

	else:

		new['userEnable'] = 'FALSE';

	if (TD["new"]["admin"]):

		new['omfAdmin'] = 'TRUE';

	else:

		new['omfAdmin'] = 'FALSE';

	# Modifying user

	ldif = modlist.modifyModlist(old, new);

	l.modify_s(dn,ldif);

	l.unbind_s();

except (ldap.LDAPError, plpy.SPIError), e:

	# Insert the LDAP pendency to the database.

	insert_pendency = plpy.prepare("INSERT INTO ldap_pendency (action, user_id, username, password, name, email, public_key, enable, admin, homedirectory, gidnumber, loginshell, error_description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)", ["ldap_pendency_actions_enum", "int", "text", "text", "text", "text", "text", "boolean", "boolean", "text", "int", "text", "text"]);

	pendency_data = [];

	pendency_data.append("MODIFY");

	pendency_data.append(TD["new"]["id"]);

	pendency_data.append(TD["new"]["username"]);

	pendency_data.append(TD["new"]["password"]);

	pendency_data.append(TD["new"]["name"]);

	pendency_data.append(TD["new"]["email"]);

	pendency_data.append(TD["new"]["public_key"]);

	pendency_data.append(TD["new"]["enable"]);

	pendency_data.append(TD["new"]["admin"]);

	pendency_data.append(TD["new"]["homedirectory"]);

	pendency_data.append(TD["new"]["gidnumber"]);

	pendency_data.append(TD["new"]["loginshell"]);

	pendency_data.append(str(e.message["desc"]));

	insert = plpy.execute(insert_pendency, pendency_data);

	# Send LDAP error notification.

	plpy.execute("SELECT ldap_error_notify()");$_$;


ALTER FUNCTION public.ldap_modify() OWNER TO postgres;

--
-- Name: channel_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE channel_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.channel_id_seq OWNER TO postgres;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: channel; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE channel (
    id integer DEFAULT nextval('channel_id_seq'::regclass) NOT NULL,
    modulation character varying,
    channel_number integer,
    frequency real
);


ALTER TABLE public.channel OWNER TO postgres;

--
-- Name: configurations; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE configurations (
    name character varying NOT NULL,
    value character varying NOT NULL
);


ALTER TABLE public.configurations OWNER TO postgres;

--
-- Name: ldap_pendency_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE ldap_pendency_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ldap_pendency_id_seq OWNER TO postgres;

--
-- Name: ldap_pendency; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE ldap_pendency (
    id integer DEFAULT nextval('ldap_pendency_id_seq'::regclass) NOT NULL,
    action ldap_pendency_actions_enum NOT NULL,
    user_id integer NOT NULL,
    username character varying,
    password character varying,
    name character varying,
    email character varying,
    public_key character varying,
    enable boolean DEFAULT false NOT NULL,
    admin boolean DEFAULT false NOT NULL,
    homedirectory character varying,
    gidnumber integer,
    loginshell character varying,
    error_description text
);


ALTER TABLE public.ldap_pendency OWNER TO postgres;

--
-- Name: motherboard_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE motherboard_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.motherboard_id_seq OWNER TO postgres;

--
-- Name: motherboard; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE motherboard (
    id integer DEFAULT nextval('motherboard_id_seq'::regclass) NOT NULL,
    cpu_type character varying,
    cpu_number character varying,
    cpu_hz real,
    hd_size integer,
    memory integer
);


ALTER TABLE public.motherboard OWNER TO postgres;

--
-- Name: node_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE node_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.node_id_seq OWNER TO postgres;

--
-- Name: node; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE node (
    id integer DEFAULT nextval('node_id_seq'::regclass) NOT NULL,
    control_ip character varying,
    control_mac character varying,
    cmc_ip character varying,
    hostname character varying,
    hrn character varying,
    chassis_sn character varying,
    motherboard_id integer,
    pxeimage_id integer,
    disk character varying
);


ALTER TABLE public.node OWNER TO postgres;

--
-- Name: pxeimages_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE pxeimages_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pxeimages_id_seq OWNER TO postgres;

--
-- Name: pxeimages; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE pxeimages (
    id integer DEFAULT nextval('pxeimages_id_seq'::regclass) NOT NULL,
    image_name character varying,
    short_description text
);


ALTER TABLE public.pxeimages OWNER TO postgres;

--
-- Name: reservation_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE reservation_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.reservation_id_seq OWNER TO postgres;

--
-- Name: reservation; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE reservation (
    id integer DEFAULT nextval('reservation_id_seq'::regclass) NOT NULL,
    slice_id integer,
    begin_time timestamp without time zone,
    end_time timestamp without time zone,
    "full" boolean DEFAULT false NOT NULL,
    user_id integer
);


ALTER TABLE public.reservation OWNER TO postgres;

--
-- Name: resource_reservation; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE resource_reservation (
    resource_id integer NOT NULL,
    reservation_id integer NOT NULL
);


ALTER TABLE public.resource_reservation OWNER TO postgres;

--
-- Name: resources_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE resources_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.resources_id_seq OWNER TO postgres;

--
-- Name: resources; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE resources (
    id integer DEFAULT nextval('resources_id_seq'::regclass) NOT NULL,
    real_resource_id integer NOT NULL,
    type resources_enum NOT NULL,
    status integer DEFAULT 0 NOT NULL
);


ALTER TABLE public.resources OWNER TO postgres;

--
-- Name: slice_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE slice_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.slice_id_seq OWNER TO postgres;

--
-- Name: slice; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE slice (
    id integer DEFAULT nextval('slice_id_seq'::regclass) NOT NULL,
    name character varying,
    expires timestamp without time zone
);


ALTER TABLE public.slice OWNER TO postgres;

--
-- Name: slice_resources; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE slice_resources (
    slice_id integer NOT NULL,
    resource_id integer NOT NULL
);


ALTER TABLE public.slice_resources OWNER TO postgres;

--
-- Name: slice_users; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE slice_users (
    slice_id integer NOT NULL,
    user_id integer NOT NULL
);


ALTER TABLE public.slice_users OWNER TO postgres;

--
-- Name: testbed; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE testbed (
    name character varying,
    cord_x real,
    cord_y real,
    domain character varying
);


ALTER TABLE public.testbed OWNER TO postgres;

--
-- Name: user_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE user_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.user_id_seq OWNER TO postgres;

--
-- Name: user; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE "user" (
    id integer DEFAULT nextval('user_id_seq'::regclass) NOT NULL,
    username character varying,
    password character varying,
    name character varying,
    email character varying,
    public_key character varying,
    enable boolean DEFAULT false,
    admin boolean DEFAULT false,
    homedirectory character varying,
    gidnumber integer,
    loginshell character varying DEFAULT '/bin/bash'::character varying NOT NULL
);


ALTER TABLE public."user" OWNER TO postgres;

--
-- Data for Name: channel; Type: TABLE DATA; Schema: public; Owner: postgres
--



--
-- Name: channel_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('channel_id_seq', 1, false);


--
-- Data for Name: configurations; Type: TABLE DATA; Schema: public; Owner: postgres
--

INSERT INTO configurations VALUES ('LDAP_HOST', 'localhost');
INSERT INTO configurations VALUES ('LDAP_PORT', '389');
INSERT INTO configurations VALUES ('LDAP_USER_TO_BIND', 'cn=Manager,dc=br');
INSERT INTO configurations VALUES ('LDAP_TREE', 'o=ufg,dc=br');
INSERT INTO configurations VALUES ('LDAP_PASS_TO_BIND', 'fibre2013');


--
-- Data for Name: ldap_pendency; Type: TABLE DATA; Schema: public; Owner: postgres
--



--
-- Name: ldap_pendency_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('ldap_pendency_id_seq', 1, false);


--
-- Data for Name: motherboard; Type: TABLE DATA; Schema: public; Owner: postgres
--



--
-- Name: motherboard_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('motherboard_id_seq', 1, false);


--
-- Data for Name: node; Type: TABLE DATA; Schema: public; Owner: postgres
--



--
-- Name: node_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('node_id_seq', 1, false);


--
-- Data for Name: pxeimages; Type: TABLE DATA; Schema: public; Owner: postgres
--



--
-- Name: pxeimages_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('pxeimages_id_seq', 1, false);


--
-- Data for Name: reservation; Type: TABLE DATA; Schema: public; Owner: postgres
--



--
-- Name: reservation_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('reservation_id_seq', 1, false);


--
-- Data for Name: resource_reservation; Type: TABLE DATA; Schema: public; Owner: postgres
--



--
-- Data for Name: resources; Type: TABLE DATA; Schema: public; Owner: postgres
--



--
-- Name: resources_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('resources_id_seq', 1, false);


--
-- Data for Name: slice; Type: TABLE DATA; Schema: public; Owner: postgres
--



--
-- Name: slice_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('slice_id_seq', 1, false);


--
-- Data for Name: slice_resources; Type: TABLE DATA; Schema: public; Owner: postgres
--



--
-- Data for Name: slice_users; Type: TABLE DATA; Schema: public; Owner: postgres
--



--
-- Data for Name: testbed; Type: TABLE DATA; Schema: public; Owner: postgres
--

INSERT INTO testbed VALUES ('FIBRE', -1999237.12, 123984648, 'fibre');


--
-- Data for Name: user; Type: TABLE DATA; Schema: public; Owner: postgres
--

INSERT INTO "user" VALUES (1, 'bruno@ufg.br', '{CRYPT}$1$NG/R5cMt$FalK710CrvXdjXeQ8aR791', 'Bruno Soares', 'brunosoares.inf@gmail.com', NULL, true, true, '/home/ufg.br/bruno', 1210, '/bin/bash');


--
-- Name: user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('user_id_seq', 2, false);


--
-- Name: channel_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY channel
    ADD CONSTRAINT channel_pkey PRIMARY KEY (id);


--
-- Name: configurations_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY configurations
    ADD CONSTRAINT configurations_pkey PRIMARY KEY (name);


--
-- Name: ldap_pendency_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY ldap_pendency
    ADD CONSTRAINT ldap_pendency_pkey PRIMARY KEY (id);


--
-- Name: motherboard_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY motherboard
    ADD CONSTRAINT motherboard_pkey PRIMARY KEY (id);


--
-- Name: node_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY node
    ADD CONSTRAINT node_pkey PRIMARY KEY (id);


--
-- Name: pxeimages_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY pxeimages
    ADD CONSTRAINT pxeimages_pkey PRIMARY KEY (id);


--
-- Name: reservation_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY reservation
    ADD CONSTRAINT reservation_pkey PRIMARY KEY (id);


--
-- Name: resource_reservation_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY resource_reservation
    ADD CONSTRAINT resource_reservation_pkey PRIMARY KEY (resource_id, reservation_id);


--
-- Name: resources_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY resources
    ADD CONSTRAINT resources_id_key UNIQUE (id);


--
-- Name: resources_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY resources
    ADD CONSTRAINT resources_pkey PRIMARY KEY (real_resource_id, type);


--
-- Name: slice_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY slice
    ADD CONSTRAINT slice_pkey PRIMARY KEY (id);


--
-- Name: slice_resources_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY slice_resources
    ADD CONSTRAINT slice_resources_pkey PRIMARY KEY (slice_id, resource_id);


--
-- Name: slice_users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY slice_users
    ADD CONSTRAINT slice_users_pkey PRIMARY KEY (slice_id, user_id);


--
-- Name: user_email_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY "user"
    ADD CONSTRAINT user_email_key UNIQUE (email);


--
-- Name: user_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY "user"
    ADD CONSTRAINT user_pkey PRIMARY KEY (id);


--
-- Name: user_username_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY "user"
    ADD CONSTRAINT user_username_key UNIQUE (username);


--
-- Name: ldap_add; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER ldap_add AFTER INSERT ON "user" FOR EACH ROW EXECUTE PROCEDURE ldap_add();


--
-- Name: ldap_del; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER ldap_del AFTER DELETE ON "user" FOR EACH ROW EXECUTE PROCEDURE ldap_del();


--
-- Name: ldap_modify; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER ldap_modify AFTER UPDATE ON "user" FOR EACH ROW EXECUTE PROCEDURE ldap_modify();


--
-- Name: node_motherboard_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY node
    ADD CONSTRAINT node_motherboard_id_fkey FOREIGN KEY (motherboard_id) REFERENCES motherboard(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: node_pxeimage_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY node
    ADD CONSTRAINT node_pxeimage_id_fkey FOREIGN KEY (pxeimage_id) REFERENCES pxeimages(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: reservation_slice_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY reservation
    ADD CONSTRAINT reservation_slice_id_fkey FOREIGN KEY (slice_id) REFERENCES slice(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: reservation_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY reservation
    ADD CONSTRAINT reservation_user_id_fkey FOREIGN KEY (user_id) REFERENCES "user"(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: resource_reservation_reservation_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY resource_reservation
    ADD CONSTRAINT resource_reservation_reservation_id_fkey FOREIGN KEY (reservation_id) REFERENCES reservation(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: resource_reservation_resource_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY resource_reservation
    ADD CONSTRAINT resource_reservation_resource_id_fkey FOREIGN KEY (resource_id) REFERENCES resources(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: slice_resources_resource_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY slice_resources
    ADD CONSTRAINT slice_resources_resource_id_fkey FOREIGN KEY (resource_id) REFERENCES resources(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: slice_resources_slice_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY slice_resources
    ADD CONSTRAINT slice_resources_slice_id_fkey FOREIGN KEY (slice_id) REFERENCES slice(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: slice_users_slice_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY slice_users
    ADD CONSTRAINT slice_users_slice_id_fkey FOREIGN KEY (slice_id) REFERENCES slice(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: slice_users_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY slice_users
    ADD CONSTRAINT slice_users_user_id_fkey FOREIGN KEY (user_id) REFERENCES "user"(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;


--
-- PostgreSQL database dump complete
--
